// 可持久化字典树
//  https://www.luogu.com.cn/problem/P4735
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
using ll = long long;
using T = int;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int maxn = 5 + 6e5;
const int max_size = 5 + maxn * 24;

struct Trie {
    int tot;
    int val[max_size];
    int trans[max_size][2];

    int cp(int u) { return val[++tot] = val[u], trans[tot][0] = trans[u][0], trans[tot][1] = trans[u][1], tot; }
    int insert(int root, int x) {
        root = cp(root);
        int u = root;
        for (int j = 24; j >= 0; --j) {
            int c = (x >> j) & 1, &v = trans[u][c];
            // if (v == 0) v = ++tot;
            v = cp(v);
            u = v, val[u]++;
        }
        return root;
    }

    int ask(int u, int v, int x) { // find the max ret ^ x
        int ret = 0;
        for (int j = 24; j >= 0; --j) {
            int c = (x >> j) & 1, cnt = val[trans[v][c ^ 1]] - val[trans[u][c ^ 1]];
            if (cnt > 0)
                ret += (1 << j), u = trans[u][c ^ 1], v = trans[v][c ^ 1];
            else
                u = trans[u][c], v = trans[v][c];
        }
        return ret;
    }
} te;
int root[maxn], rsiz;

int n, m;
int a[maxn], pre[maxn];

int main() {
    // freopen("main.in", "r", stdin);
    n = rad(), m = rad();
    rf(i, n) a[i] = rad(), pre[i] = a[i] ^ pre[i - 1];
    root[0] = te.insert(0, 0);
    rf(i, n) root[rsiz + 1] = te.insert(root[rsiz], pre[i]), ++rsiz;

    rf(i, m) {
        char op[5];
        scanf("%s", op);
        if (op[0] == 'A') {
            int x = rad();
            ++n, pre[n] = pre[n - 1] ^ x;
            root[rsiz + 1] = te.insert(root[rsiz], pre[n]), ++rsiz;
        } else if (op[0] == 'Q') {
            int l = rad() - 1, r = rad() - 1, x = rad();
            printf("%d\n", te.ask(l == 0 ? 0 : root[l - 1], root[r], x ^ pre[n]));
        }
    }
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}